package com.hunlian.makelove.net.api;

import android.content.Context;

import com.google.gson.Gson;
import com.hunlian.makelove.bean.UpdateBean;
import com.hunlian.makelove.net.ServiceInterfaceDef;
import com.hunlian.makelove.net.InterfaceServiceVisit;
import com.hunlian.makelove.net.ResponseCallbackListener;
import com.hunlian.makelove.net.StringResponseCallbackListener;

public class UpdataServiceVisit extends InterfaceServiceVisit{

	public UpdataServiceVisit(Context context) {
		super(context);
		setFunctionId(ServiceInterfaceDef.FUNC_ID_APK_UPDATE);
	}
	
	public void setParamters(String packageName,String versionCode){
		paramterData.put("packageName", packageName);
		paramterData.put("versionCode", versionCode);
	}

	public void getResult(final ResponseCallbackListener<UpdateBean,Object> listener) {
		doPost(getParamter(), new StringResponseCallbackListener() {
			@Override
			public void onSuccess(String data) {

				Gson gson = new Gson();
				UpdateBean bean = gson.fromJson(data,UpdateBean.class);

		        
				if(listener != null){
					listener.onSuccess(bean);
				}
			}

			@Override
			public void onFailure(String errCode, String errMessage,String str) {
				if (listener != null) {
					listener.onFailure(errCode, errMessage,str);
				}
			}
		});
	}
}
